﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Manager.master" AutoEventWireup="true" CodeFile="UpdateInfo.aspx.cs" Inherits="User_UpdateInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <%--<link href="<%= ResolveUrl("~/Styles/themes/base/ui.all.css")%>" rel="stylesheet" type="text/css" />--%>
    <script src="<%= ResolveUrl("~/Scripts/ui.core.js")%>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/ui.accordion.js")%>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/ui.datepicker.js")%>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/registerForm.js")%>" type="text/javascript"></script>

    <%--<link href="<%= ResolveUrl("~/Styles/uploadify.css")%>" rel="stylesheet" type="text/css" />--%>
    <script src="<%= ResolveUrl("~/Scripts/jquery.uploadify.v2.1.4.js")%>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/swfobject.js")%>" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(function () {
            jQuery("#updateUserInfo").accordion({
                autoHeight: false
            });
            jQuery("#txtbirthday").datepicker({ changeMonth: true, changeYear: true, maxDate: '-18y' });
            jQuery("#btnUpdateBasic").click(function () {
                var bValid = true;
                var fullname = jQuery("#txtFullname").val();
                var birthday = jQuery("#txtbirthday").val();
                var username = jQuery("#<%=hndusername.ClientID %>").val();
                var avatar = jQuery("#hdnavatar").val();
                if (fullname == "" && birthday == "" && avatar == "") {
                    var error = '<%= ResolveUrl("~/images/img_7.png")%>';
                    jQuery("#diverror").html("<img src='" + error + "' />&nbsp;Nhập thông tin").delay(5000).fadeOut("slow"); ;
                }
                else {
                    if (fullname != "") {
                        bValid = bValid && checkLength("txtFullname", "lblFullname", 10, 50);
                    }
                    if (birthday != "") {
                        bValid = bValid && checkLength("txtbirthday", "lblbirthday", 8, 10);
                    }
                    if (bValid) {
                        var loader = '<%= ResolveUrl("~/images/ajax-loader.gif")%>';
                        jQuery("#diverror").html("<div style='color:#0577B6'><img src='" + loader + "' />&nbsp;Đang cập nhật</div>");
                        jQuery.ajax({
                            type: "POST",
                            url: '<%= ResolveUrl("~/UpdateInfo.asmx/UpdateBasicInfo")%>',
                            data: "{username:'" + username + "',Fullname:'" + fullname + "',Birthday:'" + birthday + "'}",
                            contentType: "application/json; charset=utf-8",
                            success: function (response) {
                                var item = response.d;
                                if (item) {
                                    error = '<%= ResolveUrl("~/images/icon_success.gif")%>';
                                    jQuery("#diverror").html("<div style='color:#0577B6'><img src='" + error + "' />&nbsp;Cập nhật thành công</div>").delay(5000).fadeOut("slow");
                                }
                                else {
                                    jQuery("#diverror").html("<img src='" + error + "' />&nbsp;Cập nhật lỗi").delay(5000).fadeOut("slow"); ;
                                }
                            }
                        });
                    }
                }
                return false;
            });
            jQuery("#txtphone").keydown(function (event) {
                if (event.keyCode == 46 || event.keyCode == 8) {
                    // let it happen, don't do anything
                }
                else {
                    if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
                        event.preventDefault();
                    }
                }
            });
            jQuery("#btnUpdateContactInfo").click(function () {
                var bValid = true;
                var address = jQuery("#txtaddress").val();
                var phone = jQuery("#txtphone").val();
                var YH = jQuery("#txtYH").val();
                var skype = jQuery("#txtskype").val();
                var username = jQuery("#<%=hndusername.ClientID %>").val();
                if (address == "" && YH == "" && skype == "" && phone == "") {
                    var error = '<%= ResolveUrl("~/images/img_7.png")%>';
                    jQuery("#diverror").html("<img src='" + error + "' />&nbsp;Nhập thông tin");
                }
                else {
                    if (address != "") {
                        bValid = bValid && checkLength("txtaddress", "lbladdress", 10, 100);
                    }
                    if (YH != "") {
                        bValid = bValid && checkLength("txtYH", "lblYH", 5, 50);
                    }
                    if (skype != "") {
                        bValid = bValid && checkLength("txtskype", "lblskype", 5, 50);
                    }
                    if (phone != "") {
                        bValid = bValid && checkLength("txtphone", "lblphone", 10, 20);
                        bValid = bValid && checkPhoneNumber("txtphone", "Số điện thoại không đúng định dạng");
                    }
                    if (bValid) {
                        var loader = '<%= ResolveUrl("~/images/ajax-loader.gif")%>';
                        jQuery("#diverror").html("<div style='color:#0577B6'><img src='" + loader + "' />&nbsp;Đang cập nhật</div>");
                        jQuery.ajax({
                            type: "POST",
                            url: "UpdateInfo.asmx/UpdateContactInfo",
                            data: "{username:'" + username + "',address:'" + address + "',phoneNum:'" + phone + "',yahoochat:'" + YH + "',skypechat:'" + skype + "'}",
                            contentType: "application/json; charset=utf-8",
                            success: function (response) {
                                var item = response.d;
                                if (item) {
                                    error = '<%= ResolveUrl("~/images/icon_success.gif")%>';
                                    jQuery("#diverror").html("<div style='color:#0577B6'><img src='" + error + "' />&nbsp;Cập nhật thành công</div>").delay(5000).fadeOut("slow");
                                }
                                else {
                                    jQuery("#diverror").html("<img src='" + error + "' />&nbsp;Cập nhật lỗi").delay(5000).fadeOut("slow"); ;
                                }
                            }
                        });
                    }
                    return false;
                }
            });
        });
    </script>
    <style type="text/css">
        .ui-widget-content a {
            color: #FFFFFF;
        }
    </style>
    <%--<link href="<%= ResolveUrl("~/Styles/uploader.css")%>" rel="stylesheet" type="text/css" />--%>
    <div style="margin:0 auto">
        <div class="content_area1">
            <h1>Cập nhật thông tin</h1>
                <div id="diverror" class="login-error"></div>
                <br class="clear" />
            <div id="updateUserInfo" style="margin:5px 20px;">
                <h3><a href="#">Thông tin cơ bản</a></h3>
                <div id="divPrivacy">
                    <div class="rows">
                        <span class="leftrow"><label id="lblFullname">Họ tên</label></span>
                        <span class="rightrow"><input type="text" id="txtFullname" /></span>
                    </div>
                    <br class="clear" />
                    <div class="rows">
                        <span class="leftrow"><label id="lblbirthday">Ngày sinh</label></span>
                        <span class="rightrow"><input type="text" id="txtbirthday" readonly="readonly" /></span>
                    </div>
                    <br class="clear" />
                    <div class="rows">
                        <span class="leftrow">Hình đại diện</span>
                        <span class="rightrow" style="width:390px;">
                            <asp:FileUpload ID="FileUpload1" runat="server" />
                            <a href="javascript:jQuery('#<%=FileUpload1.ClientID%>').uploadifyUpload();">Upload Files</a>
                            <div id="pane1"></div>
                            <script type = "text/javascript">
                                jQuery(document).ready(function () {
                                    jQuery("#<%=FileUpload1.ClientID%>").uploadify({
                                        'uploader': '<%= ResolveUrl("~/uploadify/uploadify.swf")%>',
                                        'script': '<%= ResolveUrl("~/uploadify/uploadfile.ashx")%>',
                                        'cancelImg': '<%= ResolveUrl("~/uploadify/cancel.png")%>',
                                        'folder': '<%= ResolveUrl("~/User/avatar")%>',
                                        'sizeLimit': 512000,
                                        'buttonText': 'Select files',
                                        'method': 'post',
                                        'multi': false,
                                        'auto': true,
                                        'queueSizeLimit': 1,
                                        'fileExt': '*.jpg;*.gif;*.png;*.jpeg',
                                        'fileDesc': 'Image Files',
                                        'wmode': 'transparent',
                                        'scriptData': { 'name': jQuery("#<%=hndusername.ClientID %>").val() },
                                        onSelect: function (evt, queueID, fileObj, response, data) {
                                            jQuery("#pane1").html("");
                                            jQuery("#hdnavatar").val(fileObj.name);
                                        },
                                        onComplete: function (evt, queueID, fileObj, response, data) {
                                            jQuery("#hdnavatar").text(fileObj.name);
                                            var path = '<%= ResolveUrl("~/User/avatar")%>';
                                            console.log(path + "/" + jQuery("#<%=hndusername.ClientID %>").val() + "_" + fileObj.name);
                                            var str = "<div><img style='width:80px; height:80px;' src='" + path + "/" + jQuery("#<%=hndusername.ClientID %>").val() + "_" + fileObj.name + "' alt='' class='thumbs' /></div>";
                                            jQuery("#pane1").append(str);
                                        },
                                        'onAllComplete': function (event, data) {

                                        }
                                    });
                                });
                            </script> 
                        </span>
                    </div>
                    <br class="clear" />
                    <div style="margin-left:150px; margin-top:5px;">
                        <div class="LeftOfButton">
                            <div class="RightOfButton">
                                <div class="MidOfButton">
                                    <a href="#" id="btnUpdateBasic">Cập nhật</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <br class="clear" />
                </div>
                <h3><a href="#">Thông tin liên hệ</a></h3>
                <div id="divcontact">
                    <div class="rows">
                        <span class="leftrow"><label id="lbladdress">Địa chỉ</label></span>
                        <span class="rightrow"><input type="text" id="txtaddress" /></span>
                    </div>
                    <br class="clear" />
                    <div class="rows">
                        <span class="leftrow"><label id="lblphone">Điện thoại</label></span>
                        <span class="rightrow"><input type="text" id="txtphone" /></span>
                    </div>
                    <br class="clear" />
                    <div class="rows">
                        <span class="leftrow"><label id="lblYH">Yahoo</label></span>
                        <span class="rightrow"><input type="text" id="txtYH" /></span>
                    </div>
                    <br class="clear" />
                    <div class="rows">
                        <span class="leftrow"><label id="lblskype">Skype</label></span>
                        <span class="rightrow"><input type="text" id="txtskype" /></span>
                    </div>
                    <br class="clear" />
                    <div style="margin-left:150px; margin-top:5px;">
                        <div class="LeftOfButton">
                            <div class="RightOfButton">
                                <div class="MidOfButton">
                                    <a href="#" id="btnUpdateContactInfo">Cập nhật</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <br class="clear" />
                </div>
                <h3><a href="#">Sở thích</a></h3>
                <div id="divhobit">
                
                </div>
            </div>
            <br class="clear" />
            <img src="<%= ResolveUrl("~/images/bottom.jpg")%>" align="absbottom" alt="" />
        </div>
    </div>
    <asp:HiddenField ID="hndusername" runat="server" />
    <input id="hdnavatar" type="hidden" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>

